package mop.domain.user;

import mop.exception.*;

/**
 * Class for User
 * 
 * @invar name is valid
 * 	|hasValidName()
 */
public class User 
{
	
	/**
	 * Create a user with a name and description
	 * 
	 * @param name
	 *  the name of the user
	 *  
	 * @effect set the name
	 *  
	 * @throws IllegalNameException 
	 *       if the name isn't a non empty string
     *       |!isValidName(name) 
	 *       
     *       
	 */
	public User(String name) throws IllegalNameException
	{
		this.setName(name);
	}

	
	/***************************************************************************
	 * 							user name
	 ***************************************************************************/
	
	/**
	 * returns the name for this user
	 * 
	 * @return name;
	 */
	public String getName()
	{
		return this.name;
	}
	
	 /**
	  * checks if the passed name is ok
	  * 
	  * @param name
	  *  the name you want checked
	  * 
	  * @return true if the passed name is not empty and its not null
	  */
	 public static boolean isValidName(String name)
	 {
		 return ((!(name.trim().equals("")) && name != null));
	 }
	
	 /**
	  * set the name
	  * 
	  * @param name
	  *  the name for the user 
	  *  
	  * @post the name is set to the passed one
	  *  
	  * @throws IllegalNameException 
	  *       if the name isn't ok
	  *       |!isValidName(name)
	  *    
	  */
	 private void setName(String name) throws IllegalNameException
	 {

		 if(!isValidName(name))
		 {
			 throw new IllegalNameException(name);
		 }
		 this.name = name;
	 }
	
	 /**
	  * variable for the name of the user
	  */
	private String name;
	
	
	/***************************************************************************
	 * 						Java Object interface
	 ***************************************************************************/
	
	/**
	 * return a string containing all data of the user
	 * 
	 * @return a string with on the first line name
	 */
	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		sb.append(this.getName()+"\n");
		return sb.toString();
	}
	
}

